package cn.alpha.intell.rbtlib.share;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import cn.alpha.intell.rbtlib.broadcast.OSApp;

/**
 * Created by zhangxiliang on 2016/11/9.
 */
public class ShareUtil {


    private static final String SHARE_ACTION="cn.alpha.intell.robot.share";
    private static final String START_ACTION="cn.alpha.intell.robot.start";

    private static final String SHARE_ACTIVITY=".ui.chatting.ChattingActivity";


    public static void shareToChat(Context context, Contact contact, OSApp fromApp){
        ComponentName componentName = new ComponentName(
                OSApp.IM.getValue(),
                OSApp.IM.getValue()+SHARE_ACTIVITY);
        Intent intent = new Intent();
        intent.setAction(SHARE_ACTION);
        intent.putExtra(ShareContentResolver.getInstance().KEY, contact);
        intent.setComponent(componentName);
        context.startActivity(intent);
    }


    public static void startApp(Context context,  OSApp App,String activity){
        ComponentName componentName = new ComponentName(
                App.getValue(),
                App.getValue()+activity);
        Intent intent = new Intent();
        intent.setAction(START_ACTION);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setComponent(componentName);
        try {
            ((Activity)context).startActivity(intent);
        }catch (Exception e){

        }
    }

}
